<?php
declare(strict_types=1);

/**
 * 管理后台路由
 */

use Hyperf\HttpServer\Router\Router;

/**
 * @param string $controller
 * @return void
 */
function addCrudRoutes(string $controller)
{
    Router::post('/pageList', [$controller, 'pageList']);
    Router::post('/detail', [$controller, 'detail']);
    Router::post('/add', [$controller, 'add']);
    Router::post('/update', [$controller, 'update']);
    Router::post('/del', [$controller, 'del']);
}

Router::addGroup('/auth', function () {
    // 后台登录
    Router::addGroup('/admin/login', function () {
        Router::post('/pwd', [\App\Controller\Auth\Admin\LoginController::class, 'pwd']);
        // 退出登录
        Router::post('/out', [\App\Controller\Auth\Admin\LoginController::class, 'out']);
        Router::post('/refreshToken', [\App\Controller\Auth\Admin\LoginController::class, 'refreshToken']);
    });
});

Router::addGroup('/admin', function () {

    // 通用功能
    Router::addGroup('/common', function () {
        // 功能配置
        Router::addGroup('/setting', function () {
            addCrudRoutes(\App\Controller\Admin\Common\SettingController::class);
            Router::post('/refreshAll', [\App\Controller\Admin\Common\SettingController::class, 'refreshAll']);
        });

        // 功能配置
        Router::addGroup('/category', function () {
            addCrudRoutes(\App\Controller\Admin\Common\CategoryController::class);
            Router::post('/all', [\App\Controller\Admin\Common\CategoryController::class, 'all']);
            Router::post('/refreshAll', [\App\Controller\Admin\Common\CategoryController::class, 'refreshAll']);
        });
    });

    // 权限
    Router::addGroup('/rbac', function () {
        // 管理员账号
        Router::addGroup('/manager', function () {
            addCrudRoutes(\App\Controller\Admin\Rbac\ManagerController::class);
            Router::post('/updateLoginPwd', [\App\Controller\Admin\Rbac\ManagerController::class, 'updateLoginPwd']);
            Router::post('/updateIsRoot', [\App\Controller\Admin\Rbac\ManagerController::class, 'updateIsRoot']);
            Router::post('/updateSelfLoginPwd', [\App\Controller\Admin\Rbac\ManagerController::class, 'updateSelfLoginPwd']);
            Router::post('/currManagerInfo', [\App\Controller\Admin\Rbac\ManagerController::class, 'currManagerInfo']);
        });
        // 角色
        Router::addGroup('/role', function () {
            addCrudRoutes(\App\Controller\Admin\Rbac\RoleController::class);
            Router::post('/all', [\App\Controller\Admin\Rbac\RoleController::class, 'all']);
            Router::post('/bindRoutes', [\App\Controller\Admin\Rbac\RoleController::class, 'bindRoutes']);
        });
        // 路由
        Router::addGroup('/route', function () {
            addCrudRoutes(\App\Controller\Admin\Rbac\RouteController::class);
            Router::post('/all', [\App\Controller\Admin\Rbac\RouteController::class, 'all']);
        });
    });

    // 内容管理
    Router::addGroup('/content', function () {
        // 图组
        Router::addGroup('/adGroup', function () {
            addCrudRoutes(\App\Controller\Admin\Content\AdGroupController::class);
        });
        // 图
        Router::addGroup('/ad', function () {
            addCrudRoutes(\App\Controller\Admin\Content\AdController::class);
            Router::post('/all', [\App\Controller\Admin\Content\AdController::class, 'all']);
        });
        // 公告
        Router::addGroup('/notice', function () {
            addCrudRoutes(\App\Controller\Admin\Content\NoticeController::class);
        });
    });

}, [
    'middleware' => [
        \App\Middleware\ApiMiddleware::class,
        \App\Middleware\AdminAuthMiddleware::class,
    ]
]);